<!-- @format -->

<template>
    <div class="ma-content-block  p-4" style="height: 100%">
		<div v-show="props.next == 1" class="flex flex_column" style="height: 100%;">
			<a-space style="margin-bottom:16px">
				<div>筛选条件：</div>
				<!-- :load-more="loadMore" -->
				<a-select v-model="spaceValue" :options="spaceArr" :filter-option="filterOption" :style="{width:'600px'}" placeholder="请选择..."  @change="handlechange" path-mode allow-search />
			</a-space>
			<div style="display: flex; align-items: center; margin-bottom:16px;">
				<div style="margin-right:8px">提货方式：</div>
				<div style="width:600px">
					<a-select
						v-model="pick_typeid"
						placeholder="请选择"
						@change="handleChange"
					>
						<a-option
							v-for="(item,index) in pick_type"
							:key="index"
							:disabled="item.disabled"
							:value="item.key"
							:label="item.title"
						/>
					</a-select>
				</div>
			</div>
			<div class="flex" style="margin-bottom:16px;" v-if="pick_typeid == 2 || pick_typeid == 4">
				<div>配送信息：</div>
				<div class="flex flex_1">
					<a-select :style="{width:'600px'}" v-model="peisongDeptid" :options="peisongDeptlist" :field-names="{value: 'id', label: 'name'}"  allow-clear allow-search
					placeholder="配送公司" />
					<!-- <a-select style="flex:1;width: 0;" v-model="peisongaddrr" :options="peisongaddrrList" :field-names="{value: 'id', label: 'address'}"  allow-clear allow-search 
					placeholder="配送地址"  @change="handlechangeaddrrs"/> -->
				</div>
			</div>
			<div style="display: flex; margin-bottom:16px;" >
				<div style="display: flex; align-items: center; ">
					<div style="margin-right:8px">是否还箱：</div>
					<a-radio-group v-model="is_retrun" :options="retrunOptions" />
				</div>
			</div>
			<div style="display: flex; margin-bottom: 16px;" v-if="process_timeShow">
				<div style="display: flex; align-items: center; ">
					<div style="margin-right:8px">办理时间：</div>
					<a-date-picker
						style="width: 220px;"
						:defaultValue='tool.dateFormat(
							Math.round(new Date().getTime() / 1000).toString(),
							"yyyy-MM-dd"
						)'
						format="YYYY-MM-DD"
						@ok="onOkprocess_time"
					/>
				</div>
			</div>
			<ma-crud :options="options" :columns="columns" ref="crudRef" :selected-keys="selected_keys?.value" @row-click="handleRowClick"  @selection-change="setSelectedKeys" > 
				<template #box="{ record }">
					<div>{{ record?.box || '-' }}</div>
					<div>{{ record?.box_type || '-' }}</div>
					<div>{{ record?.box_belong || '-' }}</div>
					<div v-if="record.transport_type == 1">{{ record?.is_empty == 1?'空箱':record?.is_empty == 2?'重箱':'' }}</div>
					<div v-else> - </div>
				</template>
				<template #goods_name="{ record }">
					<div>{{ record?.goods_name }}</div>
				</template>
				
				<template #number="{ record,rowIndex }">
					
					<div >
						<p>
							<a-tag style="margin-top: 5px" color="blue"
								>剩余件数：{{ record.number }}</a-tag
							>
						</p>
					</div>
				</template>
				<template #weight="{ record,rowIndex }">
					
					<div >
						<p>
							<a-tag style="margin-top: 5px" color="blue"
								>货重：{{ record.weight }}</a-tag
							>
						</p>
					</div>
					
				</template>
				<template #warehouse_id="{ record }">
					<div v-if="record.warehouse_link != null">
						{{ record.warehouse_link?.warehouse.name }}/{{record.warehouse_link?.horizontal_position}}-{{record?.warehouse_link.release_position}}-{{record.warehouse_link.reaches_position}}
					</div>
					<div v-else>
						
					</div>
					
				</template>
				<template #summaryCell="{ column, record, rowIndex }">
					{{
						column.dataIndex == "dept_id" ? "合计" : column.dataIndex == "weight" ? (record[column.dataIndex] - 0).toFixed(3) : record[column.dataIndex]
					}}
				</template>
			</ma-crud>
			<div class="flex justify_end" style="margin-top:16px">
				<!-- <a-button type="primary" @click="handleNext(2)" style="margin-right:16px">下一页</a-button> -->
				<a-button type="primary" @click="handlefdslBeforeOk" style="margin-right:12px">确认提交</a-button>
				<a-button type="primary" @click="handlecolse" >取消</a-button>
			</div>
		</div>
		<div v-show="props.next == 2">
			
			
			<!-- <div style="display: flex; margin-bottom: 2%;margin-top:2%;" >
				<div style="display: flex; align-items: center; ">
					<div style="margin-right:8px">是否分流：</div>
					<a-radio-group v-model="is_fenliu" :options="plainOptions" />
				</div>
			</div> -->
			
			<div style="margin-bottom: 2%;margin-top:2%;" >
				<a-row class="grid-demo" style="margin-bottom: 2%;">
					<a-col :span="8" >
						<div style="display: flex;align-items: center;">
							<div style="margin-right: 2%;">收货手机：</div>
							<a-input v-model="delivery_mobile" style="flex:1;margin-right: 2%;" placeholder="请输入收货手机" allow-clear />
						</div>
					</a-col>
					<a-col :span="8">
						<div style="display: flex;align-items: center;">
							<div style="margin-right: 2%;">收货电话：</div>
							<a-input v-model="delivery_tel" style="flex:1;margin-right: 2%;" placeholder="请输入收货电话" allow-clear />
						</div>
					</a-col>
					<a-col :span="8">
						<div style="display: flex;align-items: center;">
							<div style="margin-right: 2%;">收货单位：</div>
							<a-input v-model="delivery_unit" style="flex:1;" placeholder="请输入收货单位" allow-clear />
						</div>
					</a-col>
				</a-row>
				<a-row class="grid-demo" >
					<a-col :span="24">
						<div style="display: flex;">
							<div style="margin-right: 8px;">收货地址：</div>
							<a-textarea v-model="delivery_address" style="flex:1;" placeholder="请输入收货地址" allow-clear/>
						</div>
					</a-col>
					
				</a-row>
			</div>
			
			<div style="display:flex;justify-content: flex-end;margin-top:2%">
				<a-button type="primary" @click="handleNext(1)" style="margin-right:12px">上一步</a-button>
				<a-button type="primary" @click="handlefdslBeforeOk" style="margin-right:12px">确认提交</a-button>
				<a-button type="primary" @click="handlecolse">取消</a-button>
			</div>
		</div>
        <!-- CRUD 组件 -->
        <a-modal v-model:visible="showUpload" title="确认提交" @cancel="handleShow" :width="1000" >
            <div
				style="width: auto; padding: 24px 36px; box-sizing: border-box"
				id="crudContent"
			>
				<div
					style="display: flex; justify-content: center; margin-bottom: 40px"
				>
					<div style="font-size: 20px">{{ itemData.value?.item[0]?.dept?.name }}</div>
				</div>
				<div
					style="
						margin-bottom: 10px;
						display: flex;
						justify-content: space-between;
					"
				>
					<div>{{ itemData.value?.item[0]?.dept?.name }}：</div>
					<div>日期：{{ process_time }}</div>
				</div>
				<div style="margin-bottom: 10px" class="table">
					<table
						style="width: 100%"
					>
						<tr style="display: flex">
							<td
								style="
									flex: 1;
									display: flex;
									justify-content: center;
									align-items: center;
								"
							>
								<div>车号</div>
							</td>
							<td
								style="
									flex: 1;
									display: flex;
									justify-content: center;
									align-items: center;
								"
							>
								<div>合同号</div>
							</td>
                            <td
								
								style="
									flex: 1;
									display: flex;
									justify-content: center;
									align-items: center;
								"
							>
								<div>品名</div>
							</td>
                            
							<td
								style="
									flex: 1;
									display: flex;
									justify-content: center;
									align-items: center;
								"
							>
								<div>集装箱</div>
							</td>
							<td
								style="
									flex: 1;
									display: flex;
									justify-content: center;
									align-items: center;
								"
							>
								<div>箱型箱类</div>
							</td>
							<td
                            
								style="
									flex: 1;
									display: flex;
									justify-content: center;
									align-items: center;
								"
							>
								<div>数量(件)</div>
							</td>
                            <td
								style="
									flex: 1;
									display: flex;
									justify-content: center;
									align-items: center;
								"
							>
								<div>重量(吨)</div>
							</td>
							<!-- <td v-if="datas?.transport_type == 2" style="flex:1;display:flex;justify-content: center;align-items: center;"><div>重量(吨)</div></td> -->
						</tr>
						<tr
							v-for="(items, index) in itemData.value?.item"
							:key="index"
							style="display: flex"
						>
							<td
								style="
									flex: 1;
									display: flex;
									justify-content: center;
									align-items: center;
								"
							>
								<div>{{ items?.car_no }}</div>
							</td>
							<td
								style="
									flex: 1;
									display: flex;
									justify-content: center;
									align-items: center;
								"
							>
								<div>{{ items?.contract_no }}</div>
							</td>
							<td
								
								style="
									flex: 1;
									display: flex;
									justify-content: center;
									align-items: center;
								"
							>
								<div>
									{{ items?.goods_name }}
								</div>
							</td>
							
							
							<td
                            
								style="
									flex: 1;
									display: flex;
									justify-content: center;
									align-items: center;
								"
							>
								<div>{{ items?.box  }}</div>
							</td>
							<td
                            
								style="
									flex: 1;
									display: flex;
									justify-content: center;
									align-items: center;
								"
							>
								<div>{{ items?.box_type }}</div>
							</td>
							
							<td
								
								style="
									flex: 1;
									display: flex;
									justify-content: center;
									align-items: center;
								"
							>
								<div>{{ items?.number }}</div>
							</td>
                            <td
								
								style="
									flex: 1;
									display: flex;
									justify-content: center;
									align-items: center;
								"
							>
								<div>{{ items?.weight }}</div>
							</td>
							<!-- <td v-if="item.prediction.transport_type == 2"  style="flex:1;display:flex;justify-content: center;align-items: center;"><div>{{ item.pick_weight }}</div></td> -->
						</tr>
					</table>
					
				</div>
				<!-- <div
					style="
						margin-bottom: 10px;
						display: flex;
						justify-content: space-between;
					"
					v-if="pick_typeid == 1 || pick_typeid == 3"
				>
					<div>选中司机：</div>
					<div></div>
				</div>
				<div style="margin-bottom: 10px" class="table" v-if="pick_typeid == 1 || pick_typeid == 3">
					<table style="width: 100%">
						<tr style="display: flex">
							<td
								style="
									flex: 1;
									display: flex;
									justify-content: center;
									align-items: center;
								"
							>
								<div>司机姓名</div>
							</td>
							<td
								style="
									flex: 1;
									display: flex;
									justify-content: center;
									align-items: center;
								"
							>
								<div>司机电话</div>
							</td>
							<td
								style="
									flex: 1;
									display: flex;
									justify-content: center;
									align-items: center;
								"
							>
								<div>司机车牌号码</div>
							</td>
						</tr>
						<tr style="display: flex" v-for="(items, index) in xuanzhongDrivers"
							:key="index">
							<td
								style="
									flex: 1;
									display: flex;
									justify-content: center;
									align-items: center;
								"
							>
								<div>{{ items?.driver.driver_name }}</div>
							</td>
							<td
								style="
									flex: 1;
									display: flex;
									justify-content: center;
									align-items: center;
								"
							>
								<div>{{ items?.driver.mobile }}</div>
							</td>
							<td
								style="
									flex: 1;
									display: flex;
									justify-content: center;
									align-items: center;
								"
							>
								<div>{{ items?.car_no }}</div>
							</td>
						</tr>
					</table>
				</div> -->
			</div>
			<template #footer>
				<div class="flex justify_end">
					<a-button style="margin-right: 20px;"  @click="showUpload = false">取消</a-button>
					<a-button type="primary" style="margin-right: 20px;" @click="handleTiHuoShow">打印提货单</a-button>
					<a-button type="primary" @click="handleOk">确认提交</a-button>
    				
				</div>
			</template>
        </a-modal>

		<a-modal
			v-model:visible="tiHuoShow"
			width="auto"
			:height="800"
			:title="(pick_typeid == 2 || pick_typeid == 4)?'打印配送单':'打印提货单'"
			ok-text="打印"
			:footer="false"
		>
			<tihuos :row="itemData.value?.item" :psName = "handlepeisongDeptName(peisongDeptid)" :process_time="process_time" :pick_typeid="pick_typeid" :user="user" v-if="tiHuoShow && (pick_typeid == 2 || pick_typeid == 4)"></tihuos>
			<tihuoes :row="itemData.value?.item" :process_time="process_time" :pick_typeid="pick_typeid" :user="user" v-if="tiHuoShow && (pick_typeid == 1 || pick_typeid == 3)"></tihuoes>
		</a-modal>
    </div>
</template>
<script setup>
import { ref, reactive, onMounted,defineEmits,defineProps } from "vue";
import predictionManage from "@/api/prediction/predictionManage";
import predictionOrder from "@/api/prediction/predictionOrder";
import predictionOrderDetail from "@/api/prediction/predictionOrderDetail";
import tihuos from "@/components/tihuos/tihuos.vue"
import tihuoes from "@/components/tihuoes/tihuoes.vue"
import { request } from "@/utils/request.js";
import { Message } from "@arco-design/web-vue";
import { Notification } from "@arco-design/web-vue";
import { pinyin } from "pinyin-pro"
import { useUserStore } from "@/store";
import tool from "@/utils/tool";
import * as common from "@/utils/common";
import commonApi from "@/api/common";
import { useRouter } from 'vue-router'
const router = useRouter()
const emits = defineEmits(['upLoadSuccess','handlecolse','handleNext'])
const crudRef = ref();
const crudRefs = ref();
const tiHuoShow = ref(false)
const paiSongList = ref([])
const userStore = useUserStore();
// 当前登录的用户所有信息，包括 id 用户名 昵称 等信息
const user = userStore.user;
const timestamp = new Date().getTime();
const dept_id = ref('');
const contract_id = ref('');
const pick_typeid = ref('');
const peisongDeptlist = ref([])
const peisongDeptid = ref('')
const peisongaddrrList = ref([])
const peisongaddrr = ref('')
let pick_type = [];
let newData = "";
const env = ref(import.meta.env);
const token = ref(tool.local.get(import.meta.env.VITE_APP_TOKEN_PREFIX));
const tab = ref(1)
const goods_id = ref('');
const butt_type = ref('');
const showUpload = ref(false);
const transport_type = ref('');
const spaceArr = ref([])
const itemData = reactive({})
const drivers_id = ref();
const spaceValue = ref();
const drivers = reactive([]);
const xuanzhongDrivers = ref([]);
const selected_keys = reactive([]);
const delivery_mobile = ref();
const delivery_address = ref();
const delivery_tel = ref();
const delivery_unit = ref();
const is_retrun = ref('1');
const is_fenliu = ref('0');
const daodadi = ref('')
const process_time = ref(tool.dateFormat(
							Math.round(new Date().getTime() / 1000).toString(),
							"yyyy-MM-dd hh:mm:ss"
						))
const guanxiaqu = ref('')
const process_timeShow = ref(false)
const props = defineProps({
		next:{
            type: Number,
            default:1,
        },
    })
const handleTiHuoShow = ()=>{
	tiHuoShow.value = true
	console.log(itemData.value)
}
const plainOptions = ref([
	{label: '否', value: '0'},
	{label: '是', value: '1'}
])
const retrunOptions = ref([
	{label: '还箱', value: '1'},
	{label: '不还箱', value: '2'},
])
const handleShow = ()=>{
    showUpload.value = false
}
const handlecolse = ()=>{
	emits('handlecolse',false)
}
const filterOption = (v,option)=>{
  return option.keywords.some(keywords=>keywords.includes(v))
}
const handleNext = (e)=>{
	emits('handleNext',e)
}

const handleSuccess = (res) => {
	Message.success('导入成功')
	predictionOrderDetail.getDrivers({ dept_id: dept_id.value}).then((res) => {
        drivers_id.value = "";
		
        drivers.value = res.data;
    });
};

const onOkprocess_time = (e)=>{
	process_time.value = e
}

const handlechangeaddrrs = (e)=> {
	console.log(e )
	peisongaddrrList.value.map((v,i)=>{
		if(e == v.id){
			daodadi.value = v.daodadi
			guanxiaqu.value = v.guanxiaqu
		}
	})
} 
const handlechange = (e)=>{
	console.log(e)
	if(e[0] == 27){
		is_fenliu.value = '1'
	}else{
		is_fenliu.value = '0'
	}
    selected_keys.value = []
    dept_id.value = e
    // contract_id.value = e[1]
    // butt_type.value = e[3]
    //    获取司机列表
	predictionOrderDetail.getDrivers({ dept_id: dept_id.value}).then((res) => {
        drivers_id.value = "";
		
        drivers.value = res.data;
		console.log(drivers.value)
    });
	// handlechangeadderr()
	crudRef.value.requestData();
    
}

const handleTab = (num) =>{
	tab.value = num
	crudRef.value.requestData();
	console.log(tab.value)
}
const handleChange = ()=>{
	crudRef.value.requestData();
}

const handlechangeInput = (e,val,item)=>{
    if((val - 0) > 0){   // 输入框输入值
        let num = selected_keys.value.findIndex(items=>{
            return items == item.id
        })
        if(num == -1){
            selected_keys.value.push(item.id)
        }
    }
}


const loadMore = (option, done)=>{
    if(option.level == '公司'){   //  获取公司合同号
        request({    //  获取公司列表
        url: 'system/userContract/remote',
        method: 'post',
        data:{
            props: { label: "name", value: "id" },
            openPage: false,
            remoteOption: {
                sort: { id: "desc" }, // 如果不指定排序方式，默认为正序排序
                select: ["id", "name"],
                filter: {
                    dept_id: ["=", option.value],
                },
                relations: [],
            },
        }
        }).then(res=>{
            let arr = [];
            res.data.map((v,i)=>{
                arr.push({value:v.id,label:v.name,dept_id:option.value,level:'合同',isLeaf: true})
            })
            const nodes = arr
            
            done(nodes)
        })
        
        

        
    }else if(option.level == '合同'){   //  获取品名
        request({    //  获取公司列表
            url: 'system/userContractGoods/index',
            method: 'get',
            params:{
                page: 1,
                pageSize: 1000,
                contract_id: option.value,
                order: 'created_at',
                orderType: 'desc',
            }
        }).then(res=>{
            let arr = [];
            res.data.items.map((v,i)=>{
                arr.push({value:v.goods_id,label:v.goods.name + '-' + v.goods.sku,level:'品名',isLeaf: true})
            })
            const nodes = arr
            done(nodes)
        })
    }
	
}
const setSelectedKeys = (val) => {
	selected_keys.value = val;
};
const handleRowClick = (row,ev) => {
	selected_keys.value = toggleElement(selected_keys.value,row.id)
}
const toggleElement = (arr,element) =>{
	return arr.includes(element)
    ? arr.filter(item => item !== element)  // 存在：过滤掉所有匹配项
    : [...arr, element]; 
}
const open = (row) => {
    // crudRef.value.requestData();
    console.log('row',row)
    transport_type.value = row == 1?2:1
    drivers.value = []
    drivers_id.value = "";
	is_fenliu.value = '0'
	daodadi.value = ''
	peisongDeptid.value = ''
	peisongaddrr.value =''
	process_time.value = tool.dateFormat(
							Math.round(new Date().getTime() / 1000).toString(),
							"yyyy-MM-dd hh:mm:ss"
						)
	guanxiaqu.value = ''
	process_timeShow.value = false
    let arr = [];
    request({    //  获取公司列表
      url: 'system/dept/getDeptList',
      method: 'get',
      params:{
        props: { label: "name", value: "id" },
        openPage: false,
        remoteOption: {
            sort: { id: "desc" }, // 如果不指定排序方式，默认为正序排序
            select: ["id", "name"],
            filter: {
                type: ["=", 2],
				status: ["=",1]
            },
            relations: [],
        },
      }
    }).then(async res=>{
		console.log('公司列表：',res)
        res.data.map((v,i)=>{
			let children = []
			v.contract.map((vv,ii)=>{
				children.push({value:vv.id,label:vv.name})
			})
			if(v.status == 1){
                arr.push({value:v.id,label:v.name,children:children})
            }
			
        })
		arr.map((v,i)=>{
				v.keywords = [
				v.label,
				pinyin(v.label,{toneType:'none',pattern:'first'}).split(' ').join(''),
				pinyin(v.label,{toneType:'none',pattern:'first'}).split(' ').join('').toUpperCase()
				]
		})
        spaceArr.value = arr
        let pick_types = await commonApi.getDict("pick_type");
        pick_type = pick_types.data.slice(0, 2)
        pick_typeid.value = '1';
        selected_keys.value = []
        spaceValue.value = ''
		process_timeShow.value = true
        dept_id.value = '999999'
        contract_id.value = '999999'
        crudRef.value.requestData()
    })
	peisongDeptid.value = ''
	
	peisongaddrr.value = ''
	peisongDeptlist.value = []
	
	peisongaddrrList.value = []
	handlepeisongDeptlist()
};

const handlepeisongDeptName = (id) =>{
	let name = ''
	peisongDeptlist.value.map((v,i)=>{
		if(v.id == id){
			name = v.name
		}
	})
	return name
}

const handlepeisongDeptlist = () =>{
	request({
		url: 'system/dept/remote',
		method: 'post',
		data: {
		openPage: false,
		remoteOption: {
			filter: {
			type: ['=', 3],
			status: ['=',1]
			},
			select: ["id", "name"],
			sort: { id: "desc" }
		}
		}
	}).then(res => {
		peisongDeptlist.value = res.data
		
	})
}

const handlechangeadderr = () =>{   // 获取合同配送地址
	request({
		url: '/system/userContractAddress/index?contract_id=' + contract_id.value,
		method: 'get',
	}).then(res=>{
		peisongaddrr.value = ''
		peisongaddrrList.value = res.data.items
	})
}
const handlefdslBeforeOk = async (e) => {
    let datas = []
	console.log(crudRef.value)
    let _data = crudRef.value.getTableData()
    if(selected_keys.value.length == 0){
        return Message.error("请选择品名！")
    }
    if(pick_typeid.value == ''){
        return Message.error("请选择提货方式！")
    } 
	if(process_time.value == ''){
		return Message.error("请选择办理时间！")
	}
	if(pick_typeid.value == 2 || pick_typeid.value == 4){
		if(peisongDeptid.value == ''){
			return Message.error("请选择配送公司！")
		}
		// if(peisongaddrr.value == ''){
		// 	return Message.error("请选择配送地址 ！")
		// }
	}
	let options = {}
	if(pick_typeid.value == 1 || pick_typeid.value == 3){
		let car_ids = JSON.parse(JSON.stringify(drivers_id.value))
		if(car_ids.length != 0){
			car_ids.shift()
			xuanzhongDrivers.value = []
			drivers.value.map((v,i)=>{
				car_ids.map((vv,ii)=>{
					if(vv == v.id){
						xuanzhongDrivers.value.push(v)
					}
				})
			})
			car_ids = car_ids.join(",")
			options.car_ids = car_ids
		}
		
	}
    
    _data.map((v,i)=>{
        selected_keys.value.map((vv,ii)=>{
            if(v.id == vv){
                v.number = v.numbers
                v.weight = v.weights
                datas.push(v)
            }
            
        })
    })
    let number = 0
    let weight = 0
    datas.map((v,i)=>{
        number += (v.number - 0)
        weight += (v.weight - 0)
    })
	number = number
	weight = weight.toFixed(3)
    datas.push({car_no:'合计',contract_no:'',goods_name:'',box:'',box_type:'',number,weight})
    let num = datas.findIndex(item =>{
        return item.number == 0 || item.weight == 0
    })
    if(num > 0){
        return Message.error("提货件数或重量不能为0！")
    }
	
    options.item = datas
    options.leixing = {
            pick: {
                _rawValue:pick_typeid.value
            },
        },
        
        
    itemData.value = options
    newData = tool.dateFormat(
			Math.round(new Date().getTime() / 1000).toString(),
			"yyyy-MM-dd hh:mm:ss"
		);
  
    
    showUpload.value = true
    // xuanzhongDrivers
    // let cc = await predictionOrder.save(options);
    // if (cc.success) {
    //     pick_typeid.value = '1';
    //     selected_keys.value = []
    //     spaceValue.value = []
    //     dept_id.value = '999999'
    //     contract_id.value = '999999'
    //     goods_id.value = '999999'
    //     butt_type.value = '999999'
    //     crudRef.value.refresh();

    //     return Message.success("过轨受理成功！");
        
    // } else {
    //     selected_keys.value = []
        
    //     crudRef.value.refresh();
    //     return Message.error("过轨受理失败！");
        
    // }
};
const handleOk = async ()=>{
	
	if(delivery_unit.value == '' ){
		Message.error('请输入收货单位')
	}
	let item = {}
	if(pick_typeid.value == 1 || pick_typeid.value == 3){
		item = {
			item:[...itemData.value.item],
			leixing:itemData.value.leixing,
			car_ids:itemData.value.car_ids,
			// is_fenliu:is_fenliu.value,
			is_retrun:is_retrun.value,
			delivery_unit:delivery_unit.value,
			delivery_tel:delivery_tel.value,
			process_time:process_time.value,
			delivery_address:delivery_address.value,
			delivery_mobile:delivery_mobile.value,
			type:1
		}
	}else{
		item = {
			item:[...itemData.value.item],
			leixing:itemData.value.leixing,
			peisong_dept_id:peisongDeptid.value,
			address_id:peisongaddrr.value,
			// is_fenliu:is_fenliu.value,
			is_retrun:is_retrun.value,
			process_time:process_time.value,
			delivery_unit:delivery_unit.value,
			delivery_tel:delivery_tel.value,
			delivery_address:delivery_address.value,
			delivery_mobile:delivery_mobile.value,
			type:1
		}
	}
	
	
	
	item.item.pop()
    let cc = await predictionOrder.save(item);
    if (cc.success) {
        pick_typeid.value = '1';
        selected_keys.value = []
        spaceValue.value = ''
        drivers.value = []
        drivers_id.value = ''
		is_retrun.value = '1'
        dept_id.value = '999999'
        contract_id.value = '999999'
        // butt_type.value = '999999'
        crudRef.value.refresh();
		showUpload.value =  false
		emits('handlecolse',false)
		router.push('/prediction/order')
        return Notification.success("办理提货成功！");
        
    } else {
        selected_keys.value = []
        
        crudRef.value.refresh();
        return Notification.error("办理提货失败！");
        
    }
}

const numberOperation = (newValue, id, numberName) => {
	predictionManage
		.numberOperation({ id, numberName, numberValue: newValue })
		.then((res) => {
			res.success && Message.success(res.message);
		})
		.catch((e) => {
			console.log(e);
		});
};

const switchStatus = (statusValue, id, statusName) => {
	predictionManage
		.changeStatus({ id, statusName, statusValue })
		.then((res) => {
			res.success && Message.success(res.message);
		})
		.catch((e) => { });
};

const options = ref({
    id: "flyos_prediction_manage",
    rowSelection: {
        showCheckedAll: true,
    },
    pk: "id",
	searchColNumber:5,
    operationColumn: false,
	scroll:{x:'100%',y:260},
    autoRequest:false,
    operationWidth: 160,
    isDbClickEdit: false,
    bordered:{ wrapper: true, cell: true },
    showSummary: true,
	summary: [
		{
			dataIndex: "number",
			action: "sum",
		},
		{
			dataIndex: "weight",
			action: "sum",
		},
	],
    formOption: {
        viewType: "modal",
        width: 600,
    },
    api: predictionManage.getList,
	recycleApi: predictionManage.getRecycleList,
    beforeRequest: (params) => {
		// params.dept_id = dept_id.value;
		params.dept_id = spaceValue.value  || '999999';
		params.transport_type = '';
		params.service_type = pick_typeid.value;
        params.is_tihuo=1;
	},
    afterRequest: (params) => {
		params.map((v, i) => {
			if(v.load_detail == null){   // 未生成装卸任务
				v.load = 3
			}else if(v.load_detail.detail_load_status == 0){ // 已生成装卸任务
				v.load = 2
			}else if(v.load_detail.detail_load_status == 1){ // 已生成装卸任务
				v.load = 1
			}
            v.numbers = v.number
            v.weights = v.weight
			if((v.number - 0 == 0) || (v.weight - 0 == 0)){
				v.disabled = true
			}
			v.weight = (v.weight - 0).toFixed(3)
		});
	},
});

const columns = ref([
	{
		title: "ID",
		dataIndex: "id",
		formType: "input",
		addDisplay: false,
		editDisplay: false,
		hide: true,
		commonRules: {
			required: true,
			message: "请输入ID",
		},
	},
	
    {
		title: "车号",
		dataIndex: "car_no",
		fixed: "left",
		align: "center",
		formType: "input",
		search: true,
	},
	{
		title: "装卸任务",
		dataIndex: "load",
		align: "center",
		formType: "select",
		width:100,
		search: true,
		fixed: "left",
		addDisplay: false,
		dict: {
		data() {
			return [
			{ label: "无", value: 3 },
			{ label: "未完成", value: 2 },
			{ label: "已完成", value: 1 },
			];
		},
		translation: true,
		tagColors: {
			1: "gray",
			2: "red",
			3: "green",
		},
		},
	},
	{
		title: "支付状态",
		dataIndex: "prediction_pay_status",
		formType: "select",
		align: "center",
		addDisplay: false,
		fixed: "left",
		search: false,
		dict: {
		name: "prediction_pay_status",
		props: {
			label: "title",
			value: "key",
		},
		translation: true,
		tagColors: {
			0: "red",
			1: "green",
		},
		},
	},

	{
		title: "品名",
		dataIndex: "goods_name",
		formType: "input",
		width:160,
		align: "center",
		search: true
	},
	
    {
		title: "数量（件）",
		dataIndex: "number",
		formType: "input",
		align: "center",
        width: 184,
        search: false,
		// search: true
	},
	{
		title: "货重（吨）",
		dataIndex: "weight",
		align: "center",
        width: 184,
		formType: "input",
		//search: true
	},
    {
		title: "箱号",
		dataIndex: "box",
		formType: "input",
		width:160,
		align: "center",
		search: true,
	},
	{
		title: "车厢位置",
		dataIndex: "transport_number",
		formType: "input",
		align: "center",
		search: false,
	},
	{
		title: "作业线路",
		dataIndex: "work_line",
		formType: "input",
		align: "center",
		search: false,
	},
	{
		title: "仓库位置",
		dataIndex: "warehouse_id",
		formType: "input",
		align: "center",
		search: false,
		addDisplay: false,
		editDisplay: false,
	},
	{
		title: "原始凭证号",
		dataIndex: "batch_no",
		width:180,
		align: "center",
        search: false,
		addDisplay: false,
		editDisplay: false,
	},
	{
		title: "原票号",
		dataIndex: "ticket_number",
		width:180,
		align: "center",
		formType: "input",
        search: false,
		commonRules: {
			// required: true,
			message: "请输入原票号",
		},
	},
	{
		title: "巡查状态",
		dataIndex: "check_status",
		formType: "select",
		align: "center",
		addDisplay: false,
		editDisplay: false,
        search: false,
		dict: {
			name: "check_status",
			props: {
				label: "title",
				value: "key",
			},
			translation: true,
		},
	},
	{
		title: "发站",
		dataIndex: "producer",
		align: "center",
		formType: "input",
		search: false,
	},
	{
		title: "运输方式",
		dataIndex: "transport_type",
		formType: "select",
		align: "center",
		search: false,
		dict: {
			name: "transport_type",
			props: {
				label: "title",
				value: "key",
			},
			translation: true,
		},
	},
	{
		title: "是否仓储",
		dataIndex: "serve_type",
		formType: "select",
		align: "center",
		search: false,
		dict: {
			name: "serve_type",
			props: {
				label: "title",
				value: "key",
			},
			translation: true,
		},
	},
	
	{
		title: "状态",
		dataIndex: "prediciont_status",
		formType: "select",
		align: "center",
		search: false,
		addDisplay: false,
		editDisplay: false,
		dict: {
			name: "prediciont_status",
			props: {
				label: "title",
				value: "key",
			},
			translation: true,
		},
	},
	
]);

defineExpose({ open });
</script>
<style>
.input {
	width: 100px;
	padding: 4px 12px;
	background: rgba(242, 243, 245);
	border: 1px solid rgba(242, 243, 245);
	border-radius: 4px;
	outline: none;
	/*清除input点击之后的黑色边框*/
}

.input:focus {
	background: #fff;
	border: 1px solid #1e80ff;
}
.table,
th,
tr,
td {
    padding: 0px;
    box-sizing: border-box;
    text-align: center;
    font-size: 14px;
    line-height: 20px;
}
.table {
    border-top: 1px solid rgba(0, 0, 0);
    border-left: 1px solid rgba(0, 0, 0);
    width: 100%;
}
.table td {
    padding: 6px 10px;
    word-break: break-all;
    word-wrap: break-word;
}
.table tr td {
    border-right: 1px solid rgba(0, 0, 0);
    border-bottom: 1px solid rgba(0, 0, 0);
}
.act{
	position: relative;
	color:rgba(22,93,255,1);
	
}
.act::after{
	content:'';
	position:absolute;
	width:100%;
	height:4px;
	border-radius:2px;
	bottom:-8px;
	left:0px;
	background:rgba(22,93,255,1);
}
</style>
<script>

export default { name: "prediction:station" };
</script>
